let tel = document.querySelector(".userTel");
let pass=document.querySelector(".userPW")
console.log(tel);
let isUserTel = false;
tel.onchange = function () {
  console.log("ccc");
  let uTel = tel.value;
  let reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
  if (reg.test(uTel)) {
    isUserTel = true;
  } else {
    alert("请检查手机号格式是否正确")
    isUserTel = false;
  }
}

let isPW = false;
pass.onchange = function () {
  let pw = this.value;
  let reg = /^\w{3,12}$/;
  if (reg.test(pw)) {
    isPW = true;
  } else {
    alert("密码只能0-12位的数字、字母、下划线")
    isPW = false;
  }
};


let nextBtn = document.querySelector(".regBtn")
let check=document.querySelector(".checkBtn")
console.log(nextBtn,check.checked);
nextBtn.onclick = function () {
  console.log("5665");

  if (isPW && isUserTel&&check.checked) {
    let username = tel.value;
    let password = pass.value;
    console.log(password);

    axios.get(regAPI, { params: { username, password } }).then((r) => {
      console.log(r);
      if (r.data.code == 1) {
        alert("注册成功,点击确定进入登录页登录")
        location.href = "../html/login.html";

      } else {
        alert("用户名已注册，请到登录页登录")
        location.href = "../html/login.html";

      }

    });

  }else if(isPW==false && isUserTel==false){
    alert("请检查用户名和密码是否已填写完整")
  }else if(check.checked!=true){
    
    alert("请阅读登陆协议并勾选同意")
  }

}
